1619C Wrong Addition codeforces solution in cpp
by ujjal roy
#include<bits/stdc++.h>
using namespace std;
main()
{
int t;
cin>>t;
while(t--)
{ unsigned long long int a,n=1,b,s,n1,n2,c=0,ans=0;
cin>>a>>s;
while(s>0)
{
n1=s%10;
s=s/10;
n2=a%10;
a=a/10;
if(n1<n2)
{
int r=s%10;
s=s/10;
if(r!=1) c=1;
else
{
n1+=10;
ans+=n*(n1-n2);
n*=10;
}
}
else
{
ans+=n*(n1-n2);
n*=10;
}
if(c==1) break;
}
if(a!=0) c=1;
if(c==1) cout<<"-1"<<endl;
else cout<<ans<<endl;
}
return 0;
}
0 Comments